package com.tbvtc.agriculturalcreditchainserver2025.service.impl;

import com.tbvtc.agriculturalcreditchainserver2025.service.AiService;
import org.springframework.stereotype.Service;
import org.springframework.web.reactive.function.client.WebClient;
import reactor.core.publisher.Flux;

@Service
public class    AiServiceImpl implements AiService {
    public Flux<String> sendRequest(String message)   {
        // 创建 WebClient
        WebClient client = WebClient.create("http://localhost:8080");
        Flux<String> responseFlux = client.get()
                .uri(uriBuilder -> uriBuilder
                        .path("/ai/chat")
                        .queryParam("prompt", message)
                        .build())
                .retrieve()
                .bodyToFlux(String.class);
        // 防止主线程退出（如果是简单测试）
        try {
            Thread.sleep(5000); // 等待流数据处理
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        return responseFlux;
    }
}
